package com.neuedu.springbootmy12306.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.neuedu.springbootmy12306.entity.Goods;
import com.neuedu.springbootmy12306.entity.Pager;
import com.neuedu.springbootmy12306.entity.Result;
import com.neuedu.springbootmy12306.mapper.GoodsMapper;
import com.neuedu.springbootmy12306.service.GoodsService;

@Service
@Transactional
public class GoodsServiceImpl implements GoodsService {

	@Autowired
	private GoodsMapper goodsMappger;

	@Override
	public List<Goods> findListByPager(Pager<Goods> pager) {

		return goodsMappger.findListByPager(pager);
	}

	@Override
	public Integer findTotalByPager(Pager<Goods> pager) {

		return goodsMappger.findTotalByPager(pager);
	}

	@Override
	public Result add(Goods object) {

		Result result = new Result(false, "新增商品失败！");
		boolean ret = goodsMappger.add(object);
		if (ret) {
			result = new Result(true, "新增商品成功！");
		}
		return result;
	}

	@Override
	public Result edit(Goods object) {

		Result result = new Result(false, "修改商品失败！");
		boolean ret = goodsMappger.edit(object);
		if (ret) {
			result = new Result(true, "修改商品成功！");
		}
		return result;
	}

	@Override
	public Result deleteByIds(List<Goods> ids) {

		Result result = new Result(false, "删除商品失败！");
		boolean ret = goodsMappger.deleteByIds(ids);
		if (ret) {
			result = new Result(true, "删除商品成功！");
		}
		return result;
	}

}
